package com.rimi.lyingGoShoppingMall.service.impl;

import com.rimi.lyingGoShoppingMall.bean.Product;
import com.rimi.lyingGoShoppingMall.mapper.ProductMapper;
import com.rimi.lyingGoShoppingMall.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Objects;

/**
 * @author 61919
 * @date 2020/3/3
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class ProductServiceImpl implements ProductService {

    @Autowired
    ProductMapper productMapper;

    /**
     * 寻找所有的商品
     *
     * @return
     */
    @Override
    public List<Product> findAllProducts() {
        return productMapper.findAllProduct();
    }

    @Override
    public boolean addProducts(Product product) {
        if (Objects.isNull(product)){
            return false;
        }
        int row = productMapper.addProduct(product);
        return row == 1;
    }
}
